	//-------------------------------------
	//	Admin
	//-------------------------------------

function scalate_permission( is_root, is_admin, user_id, group_id )
{
	if ( site_is_root != 1 )
	{
		if ( is_root && is_root != site_is_root )
		{
			return false;
		}
		
		if ( is_root == 0 && is_admin == 0 && site_is_admin == 1 )
		{
			return true;
		}
		else
		{
			if ( group_id && group_id == site_group_id && site_is_leader == 1 )
			{
				if ( user_id != site_user_id )
				{
					return true;	
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
	}
	
	return true;
}

function permission_btn( action, module_name, url, is_root, is_admin, user_id, group_id )
{
	if ( is_root && is_admin )
	{		
		if ( scalate_permission(is_root, is_admin, user_id, group_id) == false )
		{
			return false;	
		}
	}
	
	if ( pms[module_name+'_'+action] == 1 )
	{
		if ( action == "edit" )
		{
			if ( url.match("javascript") )
			{
				document.writeln('<a href="'+url+'"><img align="absmiddle" src="'+site_root_domain+'/images/icon_edit.png"></a>');
			}
			else
			{
				document.writeln('<a href="'+url+'&page='+site_page+'"><img align="absmiddle" src="'+site_root_domain+'/images/icon_edit.png"></a>');
			}
		}
		else if ( action == "delete" )
		{
			document.writeln('<a onclick="return alert_delete(\''+url+'&page='+site_page+'\');"><img align="absmiddle" src="'+site_root_domain+'/images/icon_delete.png"></a>');
		}
		else if ( action == "suspend" )
		{
			document.writeln('<a onclick="return alert_delete(\''+url+'&page='+site_page+'\');"><img align="absmiddle" src="'+site_root_domain+'/images/icons/icon_suspend.png"></a>');
		}
		else if ( action == "unsuspend" )
		{
			document.writeln('<a onclick="return alert_delete(\''+url+'&page='+site_page+'\');"><img align="absmiddle" src="'+site_root_domain+'/images/icons/icon_unsuspend.png"></a>');
		}
		else if ( action == "postpone" )
		{
			document.writeln('<a onclick="return alert_delete(\''+url+'&page='+site_page+'\');"><img align="absmiddle" src="'+site_root_domain+'/images/icons/icon_stop.png"></a>');
		}
		else if ( action == "continue" )
		{
			document.writeln('<a onclick="return alert_delete(\''+url+'&page='+site_page+'\');"><img align="absmiddle" src="'+site_root_domain+'/images/icons/icon_start.png"></a>');
		}
		else if ( action == "renew" )
		{
			document.writeln('<a onclick="return alert_delete(\''+url+'&page='+site_page+'\');"><img align="absmiddle" src="'+site_root_domain+'/images/icons/icon_start.png"></a>');
		}
		else if ( action == "empty" )
		{
			document.writeln('<a onclick="return alert_empty(\''+url+'\');"><img width="20" height="20" align="absmiddle" src="'+site_root_domain+'/images/icon_empty.png"></a>');
		}
		
	}
}

function permission( module_name, text, is_root, is_admin, user_id, group_id )
{
	if ( is_root && is_admin )
	{
		if ( scalate_permission(is_root, is_admin, user_id, group_id ) == false )
		{
			return false;	
		}
	}
	
	if ( parseInt(pms[module_name]) == 1 )
	{
		return text;
	}
	else
	{
		return "";	
	}
}

function permission_text( module_name, text, is_root, is_admin, user_id, group_id )
{
	if ( is_root && is_admin )
	{
		if ( scalate_permission(is_root, is_admin, user_id, group_id ) == false )
		{
			return false;	
		}
	}

	if ( pms[module_name] == 1 )
	{
		document.writeln(text);
	}
}

function sharp_url()
{
	var base_url = window.location.href;
	base_url = base_url.split("#");

	if ( ! base_url[1] )
	{
		base_url[1] = "&";
	}
	
	return base_url;
}

function count_sharp_url()
{
	var url = sharp_url();
	
	if ( url[1] == "&" )
	{
		return false;
	}
	
	var url_data = url[1].split("&");
	
	return url_data.length;	
}

function get_sharp_url( site_view )
{
	var site_view = site_view ? site_view : "murl";
	var url = sharp_url();
	var url_data = url[1].split("&");

	for ( var i = 0; i < url_data.length; i++ )
	{
		var url_detail = url_data[i].split("=");
		
		if ( site_view == url_detail[0] )
		{
			return url_detail[1];
		}
	}
	
	return false;
}

function set_sharp_url( module_name )
{
	if ( get_sharp_url() != module_name )
	{
		var base_url = sharp_url();
		var new_url = "";		
		
		if ( count_sharp_url() == false )
		{
			new_url = "#" + "murl=" + module_name;
		}
		else
		{
			new_url = "#" + base_url[1] + "&murl=" + module_name;
		}
		
		window.location.href = base_url[0] + new_url;
	}
	
	my_setcookie("sharp_url", new_url);
	
	return true;
}

function remove_sharp_url( module_name )
{
	var newurl = window.location.href;

	newurl = newurl.replace("#murl=" + module_name, "");
	newurl = newurl.replace("murl=" + module_name, "");

	my_setcookie("sharp_url", "");
	
	window.location.href = newurl+"#";
}

function auto_sharp_url()
{
	var base_url = sharp_url();
	var cookie_sharp_url = my_getcookie("sharp_url");
	
	if ( cookie_sharp_url && cookie_sharp_url != "undefined" )
	{
		//window.location.href = base_url[0] + cookie_sharp_url;
		
		my_setcookie("sharp_url", "");
	}
	
	if ( get_sharp_url() )
	{
		var data = get_sharp_url()+"();";
		eval(data);
	}
}

	//-------------------------------------
	//	DOM POPUP
	//-------------------------------------
	
	function site_alert_open( input_title, input_content, input_command )
	{
		document.getElementById("site_alertheader").style.display = (is_ie == 0 ? "table" : "block");
		Drag.init(document.getElementById("site_alertheader"));

		if ( input_title ) { document.getElementById("site_alerttitle").innerHTML = input_title; }
		if ( input_content ) { document.getElementById("site_alertcontent").innerHTML = input_content; }
		if ( input_command ) { document.getElementById("site_alertcommand").innerHTML = input_command + "<input type='button' onclick='site_alert_close()' value='"+lang_close+"' />"; }
		
		// Set center
		var displaycenter = GetCenteredXY(document.getElementById("site_alertbox").style.width,document.getElementById("site_alertbox").style.height);
		//document.getElementById("site_alertbox").style.marginLeft = (displaycenter[0]-0)+"px";
		document.getElementById("site_alertbox").style.top = (displaycenter[1]-400)+"px";
	}
	
	function site_alert_close()
	{
		document.getElementById("site_alertheader").style.display = "none";
		document.getElementById("site_alerttitle").innerHTML = "";
		document.getElementById("site_alertcontent").innerHTML = "";
		document.getElementById("site_alertcommand").innerHTML = "";
	}
	
	function site_location_dropdown( object_name, default_value, add_text, is_write, add_html )
	{
		object_name = object_name ? object_name : "site_location";
		
		var language_array = unserialize( site_location );
		
		var language_data = "";
		
		language_data += "<select class='input_text' name='"+object_name+"' id='"+object_name+"' defaultvalue='"+default_value+"'>";

		if ( add_text )
		{
			language_data += "<optgroup label='"+add_text+"'>";	
		}
		
		if ( add_html )
		{
			language_data += add_html;
		}

		for ( var i = 0; i < 10; i ++ )
		{
			if ( language_array[i] )
			{
				language_data += "<option value='"+language_array[i]+"' "+(site_default_location == language_array[i] ? "selected" : "")+">"+language_array[language_array[i]]+"</option>";
			}
			else
			{
				break;	
			}
		}
		
		language_data += "</select>";

		if ( is_write )
		{
			document.writeln(language_data);
		}
		else
		{
			return language_data;
		}
	}
	
	function change_location( object )
	{
		window.location.href = site_root_domain + "/?reset_location=" + object.options[object.selectedIndex].value;
	}
	
	function site_location_change( object_name, default_value, add_text, is_write, add_html )
	{
		object_name = object_name ? object_name : "site_location";
		
		var language_array = unserialize( site_location );
		
		var language_data = "";
		
		language_data += "<select class='input_text' style='float: left; width: 100px; background: #FFFFFF; height: 22px; margin-top: 10px; border: 0px; margin-right: 15px;' name='"+object_name+"' id='"+object_name+"' defaultvalue='"+default_value+"' onchange='change_location(this);'>";

		language_data += "<optgroup label='"+lang_section+"'>";
		language_data += "<option value='all'>"+lang_allsection+"</option>";
		
		if ( add_html )
		{
			language_data += add_html;
		}

		for ( var i = 0; i < 10; i ++ )
		{
			if ( language_array[i] )
			{
				language_data += "<option value='"+language_array[i]+"' "+(default_value == language_array[i] ? "selected" : "")+">"+language_array[language_array[i]]+"</option>";
			}
			else
			{
				break;	
			}
		}
		
		language_data += "</select>";

		if ( is_write )
		{
			document.writeln(language_data);
		}
		else
		{
			return language_data;
		}
	}
	
	function site_location_selected()
	{
		language_selected = document.getElementById("site_location").options[document.getElementById("site_location").selectedIndex].value;
		
		return language_selected;
	}
	
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}
	
	function getInnerSize() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	  return [ myWidth,  myHeight ];
	}
	
	function GetCenteredXY(w, h) {
		var ps = getScrollXY();
		var sz = getInnerSize();
		var Left = (sz[0] - w) / 2 + ps[0];
		var Top = (sz[1] - h) / 2 + ps[1];
		return [ Math.ceil(Left), Math.ceil(Top) ];
	}
	
	function preview_print(module_name, module_id)
	{
        AjaxRequest.get(
        {
        	'url':site_root_domain + "/?site=print&act="+module_name+"&id="+module_id
        	,'onLoading':function(req){ document.getElementById("printer_content").innerHTML = lang_loading; }
        	,'onSuccess':function(req){ document.getElementById("printer_content").innerHTML = req.responseText; }
        	}
        );
	}
	
	function open_print( module_name, module_id )
	{
		/*var displaycenter = GetCenteredXY(document.getElementById("printer_info").style.width,document.getElementById("printer_content").style.height+60);
		document.getElementById("printer_info").style.display = (is_ie == 0 ? "table" : "block");
		document.getElementById("printer_info").style.marginLeft = 140+"px";
		document.getElementById("printer_info").style.top = (displaycenter[1]-180)+"px";

		preview_print(module_name, module_id);*/
		
		window.location.href=site_root_domain + "/?site=print&act="+module_name+"&id="+module_id;
	}
	
	function close_print()
	{
		document.getElementById("printer_info").style.display = "none";
		document.getElementById("printer_content").innerHTML = "";
	}
	
	function submit_print()
	{
		var print_content = document.getElementById("printer_content").innerHTML;
		close_print();
		
		//var WindowObject = window.open('', "TrackHistoryData", "width=420,height=225,top=250,left=345,menubar=yes, toolbars=yes,scrollbars=no,status=no,resizable=no");
		//WindowObject.document.write(print_content);
		//WindowObject.document.close();
		//WindowObject.focus();
		//WindowObject.print();
		//WindowObject.close();
	}
	
	function check_usergroup(object, str)
    {
    	for ( var i = 0; i < document.forms[object].elements.length; i++)
		{  
            if ( str.length != str.replace("|"+document.forms[object].elements[i].value+"|", "").length == true )
			{
				document.forms[object].elements[i].checked = true;
			}
        }
    }

	var alert_task_enable = 1;
	var alert_task_slide = 1;

	function alert_task_checker()
	{
		if ( ! my_getcookie("alert_task") )
		{
			my_setcookie("alert_task", "show");	
		}
		
		alert_task_slide = 0;
		
		if ( my_getcookie("alert_task") == "hide" )
		{
			alert_task_enable = 0;
			alert_task_control();
		}
		else if ( my_getcookie("alert_task") == "show" )
		{
			alert_task_enable = 1;
			alert_task_control();
		}
		
		alert_task_slide = 1;
	}
	
	var slide_min = 0;
	var slide_max = 270;
	var slide_current = 0;
	var slide_per_time = 10;
	var slide_time = is_ie == 0 ? 10 : 5;
	var sliding = 0;
	
	function alert_task_slide_out()
	{
		if ( alert_task_slide == 0 )
		{
			document.getElementById("alert_task").style.right = -slide_max + "px";			
			return false;
		}
		
		if ( slide_current == -slide_max )
		{
			sliding = 0;			
			return false;	
		}
		
		slide_current = parseInt(slide_current-slide_per_time);
		document.getElementById("alert_task").style.right = slide_current + "px";
		
		sliding = 1;
		
		setTimeout("alert_task_slide_out()",slide_time);
	}
	
	function alert_task_slide_in()
	{
		if ( alert_task_slide == 0 )
		{
			document.getElementById("alert_task").style.right = slide_min + "px";			
			return false;
		}
		
		if ( slide_current == 0 )
		{
			sliding = 0;
			return false;	
		}
		
		slide_current = parseInt(slide_current+slide_per_time);
		document.getElementById("alert_task").style.right = slide_current + "px";
		
		sliding = 1;
		
		setTimeout("alert_task_slide_in()",slide_time);
	}

	function alert_task_control()
	{
		if ( sliding == 1 )
		{
			return false;	
		}
		
		if ( alert_task_enable == 0 )
		{
			slide_current = slide_min;
			alert_task_slide_out();
			if ( document.getElementById("alert_task_content") )
			{
				document.getElementById("alert_task_content").style.display = "none";
			}
			document.getElementById("alert_task_arrow").innerHTML = "&laquo;";
			//document.getElementById("alert_task_arrow").style.cssFloat = "left";
			my_setcookie("alert_task", "hide");
			alert_task_enable = 1;
		}
		else if ( alert_task_enable == 1 )
		{
			slide_current = -slide_max;
			alert_task_slide_in();
			if ( document.getElementById("alert_task_content") )
			{
				document.getElementById("alert_task_content").style.display = "block";
			}
			document.getElementById("alert_task_arrow").innerHTML = "&raquo;";
			//document.getElementById("alert_task_arrow").style.cssFloat = "right";
			my_setcookie("alert_task", "show");
			alert_task_enable = 0;
		}
	}
	
	//-------------------------------------
	//	TAB CHANGE
	//-------------------------------------
	
	var currenttab = "";
	
	function tabchange( elementid )
	{
		// Turn of current tab
		if ( currenttab )
		{
			// Set id for current tab
			var tabbar = document.getElementById("tab_bar").getElementsByTagName("li");

			for ( var i = 0; i < tabbar.length; i++ )
			{
				if ( tabbar[i].getAttribute("class") == "active" && ! tabbar[i].getAttribute("id") )
				{
					tabbar[i].setAttribute("onclick", "tabchange(this)");
					tabbar[i].setAttribute("id", "tab_"+currenttab);
	
					break;
				}
			}

			// Set hidden
			document.getElementById(currenttab).style.display = "none";
			remove_sharp_url("tab_"+currenttab);
		}
	
		// Turn of all tabs
		var tabbar = document.getElementById("tab_bar").getElementsByTagName("li");

		for ( var i = 0; i < tabbar.length; i++ )
		{
			tabbar[i].removeAttribute("class");
		}
		
		// Display
		object = elementid.getAttribute("id").replace("tab_", "");
		document.getElementById(object).style.display = "block";
		elementid.setAttribute("class", "active");
				
		// Set current tab
		currenttab = object;
		
		// Set sharp
		set_sharp_url(elementid.getAttribute("id"));
	}
	
	//-------------------------------------
	//	TAB CHECK
	//-------------------------------------
	
	function tabstart()
	{
		var url = get_sharp_url();
		remove_sharp_url(url);
		tabchange( document.getElementById(url) );	
	}
	
	function tabcheck()
	{
		if ( get_sharp_url() )
		{
			window.addEventListener('load', tabstart, false);
		}
	}
	
	//-------------------------------------
	//	CHECK BOX
	//-------------------------------------

	function checkbox_start(obname)
	{
		object = document.getElementById(obname);
		var cell = object.getElementsByTagName("li");
		
		for ( var i = 0; i < cell.length; i++ )
		{
			var ce = cell[i];
			var ip = ce.getElementsByTagName("input");
			ip = ip[0];

			// Set DOM
			ce.setAttribute("onclick", "checkbox_click('"+obname+"','"+ip.getAttribute("name")+"')");
						
			// Set class
			if ( ip.checked == true )
			{
				ce.setAttribute("class", "active");
			}
			else
			{
				ce.setAttribute("class", "inactive");
			}
		}
	}
	
	function checkbox_click(ob,element)
	{
		element = document.getElementById(element);

		if ( element.checked == true )
		{
			element.checked = false;
		}
		else
		{
			element.checked = true;	
		}
				
		checkbox_start(ob);
	}
	
	//-------------------------------------
	//	UPDATE STATUS
	//-------------------------------------
	
	function user_update_status(theform, user_id)
	{
		var status = AjaxRequest.submit(
		theform
		,{
			'url':theform.action
			,'onLoading':function()
			{
				document.getElementById("quote_"+user_id).innerHTML = "<img align='absmiddle' src='"+site_img_url+"/icons/icon_loading_bar.gif' />";
				document.getElementById("user_message_ajax").innerHTML = "<img align='absmiddle' src='"+site_img_url+"/icons/icon_loading_bar.gif' />";
			}
			,'onSuccess':function(req)
			{
				document.getElementById("quote_"+user_id).innerHTML = req.responseText + " <img align='absmiddle' src='"+site_img_url+"/icons/icon_loaded.png' />";
				document.getElementById("user_message_ajax").innerHTML = "<img align='absmiddle' src='"+site_img_url+"/icons/icon_loaded.png' />";
				// 
			}
		}
		);
		
		return false;
	}
	
	function user_update_profile_status(theform, user_id)
	{
		var status = AjaxRequest.submit(
		theform
		,{
			'url':theform.action
			,'onLoading':function()
			{
				document.getElementById("quote_"+user_id).innerHTML = "<img align='absmiddle' src='"+site_img_url+"/icons/icon_loading_bar.gif' />";
			}
			,'onSuccess':function(req)
			{
				document.getElementById("quote_"+user_id).innerHTML = req.responseText + "";
				//hide status form
				show_hide_status();
			}
		}
		);
		
		return false;
	}

	//-------------------------------------
	//	CHAT
	//-------------------------------------

	var chat_temptext = "";
	
	function user_check_submit(o)
	{
		var chat_form = document.getElementById("chat_form");

		if ( o.value.length > 0 )
		{
			chat_form.submit.disabled = false;
		}
		else
		{
			chat_form.submit.disabled = true;
		}
	}
	
	function user_check_enter(e)
	{
		var chat_form = document.getElementById("chat_form");

		if( window.event )
		{
			keynum = e.keyCode;
		}
		else if( e.which )
		{
			keynum = e.which;
		}

		if ( e.shiftKey == false && keynum == 13 )
		{		
			if ( chat_form.submit.disabled == false )
			{
				user_insert_chat(chat_form);
			}
			
			return false;
		}
		else
		{
			return true;	
		}
	}
	
	function user_insert_chat(theform)
	{
		var room = document.getElementById("chat_room");
		
		if ( ! theform.chat_content.value )
		{
			alert(lang_chat_incomplete_content);
			theform.chat_content.focus();
			return false;
		}
			
		var status = AjaxRequest.submit(
		theform
		,{
			'url':theform.action
			,'onLoading':function()
			{
				theform.chat_content.value = "";
				theform.submit.value = lang_chat_sending;
				theform.submit.disabled = true;
			}
			,'onSuccess':function(req)
			{
				theform.chat_content.value = "";
				theform.submit.value = lang_chat_send;
				theform.submit.disabled = true;
				room.scrollTop = room.scrollHeight;
			}
		}
		);
		
		return false;
	}

	function user_room_load()
	{
		var room = document.getElementById("chat_room");
		var is_bottom = 0;

		AjaxRequest.get(
		{
			'url':site_root_domain+"/server.php?mod=chat&"+site_user_id
			,'onLoading':function(req){  }
			,'onSuccess':function(req)
			{
				room.innerHTML = req.responseText;
				temp_text = room.innerHTML.split("<!--");
				temp_text = temp_text[temp_text.length-1];

				if ( temp_text != chat_temptext )
				{
					room.scrollTop = room.scrollHeight;
				}
				
				chat_temptext = temp_text;
				
				setTimeout('user_room_load()', 500);
			}
		}
		);
	}
	
	//-------------------------------------
	//	PROFILE STATUS
	//-------------------------------------
	
	function show_hide_status()
	{
		if (document.getElementById('status_frm').style.display == 'none')
		{
			document.getElementById('status_frm').style.display = 'block';
		}
		else
		{
			document.getElementById('status_frm').style.display = 'none';
		}
	}
	
	//-------------------------------------
	//	MENU BAR
	//-------------------------------------
	
	var task_bar_opened = 0;
	
	function task_bar_on()
	{
		task_bar_opened = 1;	
	}
	
	function task_bar_off()
	{
		task_bar_opened = 0;	
	}
	
	function task_bar_open(obname)
	{
		task_bar_opened = 0;
		task_bar_close();
		task_bar_opened = 1;
		
		if ( obname.getAttribute("id") == "task_bar_msg" )
		{
			obname.setAttribute("class", "mess_icon me_active");
		}
		else if ( obname.getAttribute("id") == "task_bar_ticket" )
		{
			obname.setAttribute("class", "ticket_icon ti_active");
		}
		else if ( obname.getAttribute("id") == "task_bar_task" )
		{
			obname.setAttribute("class", "task_icon ta_active");
		}
		
		if ( document.getElementById(obname.getAttribute("id")+"_sub") )
		{
			document.getElementById(obname.getAttribute("id")+"_sub").style.display = "block";
		}
	}
	
	function task_bar_close()
	{
		if ( task_bar_opened == 0 )
		{
			obmsg = document.getElementById("task_bar_msg");
			obticket = document.getElementById("task_bar_ticket");
			obtask = document.getElementById("task_bar_task");
			
			if ( obmsg ) { obmsg.setAttribute("class", "mess_icon"); }
			if ( document.getElementById("task_bar_msg_sub") ) { document.getElementById("task_bar_msg_sub").style.display = "none";  }
			if ( obticket ) { obticket.setAttribute("class", "ticket_icon"); }
			if ( document.getElementById("task_bar_ticket_sub") ) { document.getElementById("task_bar_ticket_sub").style.display = "none"; }
			if ( obtask ) { obtask.setAttribute("class", "task_icon"); }
			if ( document.getElementById("task_bar_task_sub") ) { document.getElementById("task_bar_task_sub").style.display = "none"; }
		}
	}